package com.weds.ticket.ticket.controller;

import com.weds.ticket.ticket.data.Repository;
import com.weds.ticket.ticket.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * @Description
 * @Author lihw
 * @Date 2025/8/14 下午5:26
 */
@RequestMapping("/stock")
@RestController
public class StockController {

    @Autowired
    private StockService stockService;

    @GetMapping("/add")
    public Object setStockData(@RequestParam("stock") String stockCodes) {
        if (!StringUtils.hasLength(stockCodes)) {
            return "stockCode is null";
        }
        String[] split = stockCodes.split(",");
        List<String> list = Arrays.asList(split);
        // Repository.stockCodes.addAll(list);
        list.forEach(Repository::addCode);

        return "success";
    }

    @GetMapping("/list")
    public Object getStockData() {
        return Repository.getCodeList();
    }

    @GetMapping("/remove")
    public Object removeStockData(@RequestParam("stock") String stockCodes) {
        if (!StringUtils.hasLength(stockCodes)) {
            return "stockCode is null";
        }
        String[] split = stockCodes.split(",");
        List<String> list = Arrays.asList(split);
        // Repository.stockCodes.removeAll(list);
        list.forEach(Repository::removeCode);
        return "success";
    }

}
